import 'package:flutter/material.dart';

class Gesture extends StatefulWidget {
  @override
  _GestureState createState() => _GestureState();
}

class _GestureState extends State<Gesture> {
  String _opertion = "No Gesture detected";
  double _top = 100;
  double _left = 100;
  @override
  Widget build(BuildContext context) {
    return Material(
      child: Column(
        children: <Widget>[
          SizedBox(
            height: 50,
          ),
          Center(
            child: GestureDetector(
              onTap: () {
                setState(() {
                  _opertion = "Tap";
                });
              },
              onDoubleTap: () {
                setState(() {
                  _opertion = "DoubleTap";
                });
              },
              onLongPress: () {
                setState(() {
                  _opertion = "LongPress";
                });
              },
              child: Container(
                color: Colors.blue,
                width: 200,
                height: 100,
                child: Text(
                  _opertion,
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ),
          Expanded(
            child: Stack(
              children: <Widget>[
                Positioned(
                  top: _top,
                  left: _left,
                  child: GestureDetector(
                      onPanDown: (e) {
                        print('开始拖拽');
                      },
                      onPanEnd: (e) {
                        print('结束拖拽');
                      },
                      onPanUpdate: (e) {
                        setState(() {
                          _top += e.delta.dy;
                          _left += e.delta.dx;
                        });
                      },
                      child: CircleAvatar(
                        child: Text("A"),
                      )),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
